/*******************************************************************************
 *
 *      Filename: test_Texture.cpp
 *   Description: Simple test for Texture class
 *        Author: [kb]ypp
 *    Created at: October 19, 2005
 * Last modified: 
 *
 ******************************************************************************/

#include "../Texture.h"

#include <cstdlib>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <GL/glut.h>

Texture *tex = 0;

void init()
{
	glClearColor( 0.0, 0.0, 0.0, 0.0 );
	glShadeModel( GL_FLAT );
	
	tex = new Texture( "../../../art/textures/r75logo.tga" );
	tex->enable();
	tex->bind();
	
	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
}

void display()
{
	glClear( GL_COLOR_BUFFER_BIT );
	
	glBegin( GL_QUADS );
		glTexCoord2f( 0.0, 0.0 );  glVertex2f( -5.0, -5.0 );
		glTexCoord2f( 1.0, 0.0 );  glVertex2f(  5.0, -5.0 );
		glTexCoord2f( 1.0, 1.0 );  glVertex2f(  5.0,  5.0 );
		glTexCoord2f( 0.0, 1.0 );  glVertex2f( -5.0,  5.0 );
	glEnd();
	
	glFlush();
}

void reshape( int w, int h )
{
	glViewport( 0, 0, static_cast< GLsizei >( w ), static_cast< GLsizei >( h ) );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glOrtho( -5.5, 5.5, -5.5, 5.5, -1.0, 1.0 );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
}

void keyboard( unsigned char key, int x, int y )
{
	switch ( key ) {
		case 27 /*Esc*/:
			exit( 0 );
			break;
		default:
			break;
	}
}

void prepareExit()
{
	delete tex;
}

int main( int argc, char *argv[] )
{
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_SINGLE | GLUT_RGBA );
	glutInitWindowSize( 300, 300 );
	glutInitWindowPosition( 100, 100 );
	glutCreateWindow( "Texture class test" );
	atexit( prepareExit );
	init();
	glutDisplayFunc( display );
	glutReshapeFunc( reshape );
	glutKeyboardFunc( keyboard );
	glutMainLoop();

	return 0;
}
